package com.example.task01_servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "CookieServlet5", value = "/cookie5")
public class CookieServlet5 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.创建Cookie对象并指定数值
        //Cookie cookie=new Cookie("name","zhaoyun");
        //3.修改Cookie的路径信息
        Cookie cookie=new Cookie("name","huangzhong");
        cookie.setPath(request.getContextPath()+"/hello");
        //2.添加到响应信息中
        response.addCookie(cookie);
        System.out.println("设置Cookie路径成功!");
    }
}
